package com.group9.controller;

import com.github.pagehelper.PageHelper;
import com.group9.dto.OrderShow;
import com.group9.dto.PageInfoResult;
import com.group9.service.OrderShowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.aggregation.ArrayOperators;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("ordershow")
public class OrderShowController {

    @Autowired
    OrderShowService orderShowService;

    /**
     * 显示全部订单
     * @return
     */
    @RequestMapping(value = "showall", method = RequestMethod.POST)
    @ResponseBody
    public List<OrderShow> orderShowList() {
        List<OrderShow> orderShowList = orderShowService.selectByCustomerIdAndOrderStatus(1001,1);
        return orderShowList;
    }

    /**
     * 显示未付款订单
     * @return
     */
    @RequestMapping(value = "showunpaid", method = RequestMethod.POST)
    @ResponseBody
    public List<OrderShow> orderShowUnpaidList() {
        List<OrderShow> orderShowList = orderShowService.selectUnpaidByCustomerIdAndOrderStatus(1001,2);
        return orderShowList;
    }

    /**
     * 显示待发货订单
     * @return
     */
    @RequestMapping(value = "showundeliver",method = RequestMethod.POST)
    @ResponseBody
    public List<OrderShow> orderShowUndeliverList() {
        List<OrderShow> orderShowList = orderShowService.selectUndeliverByCustomerIdAndOrderStatus(1001,3);
        return orderShowList;
    }

    /**
     * 显示待收货订单
     * @return
     */
    @RequestMapping(value = "showunreceive",method = RequestMethod.POST)
    @ResponseBody
    public List<OrderShow> orderShowUnreceiveList() {
        List<OrderShow> orderShowList = orderShowService.selectUnreceiveByCustomerIdAndOrderStatus(1001,4);
        return orderShowList;
    }

    /**
     * 分页信息显示
     * @param pageInfoResult
     * @return
     */
    @RequestMapping(value = "111page")
    @ResponseBody
    public PageInfoResult<OrderShow> selectAllOrders(PageInfoResult pageInfoResult){
        return orderShowService.selectAllOrders(pageInfoResult);
    }

    /**
     * 修改订单状态
     * @param orderId
     * @param orderStatus
     * @return
     */
    @RequestMapping(value = "updateorderstatus",method = RequestMethod.POST)
    @ResponseBody
    public Integer updateOrderStatus(Integer orderId, Integer orderStatus) {
        int rows = orderShowService.updateOrderStatus(orderId,orderStatus);
        if(rows == 2){
            return 1;
        } else {
            return 0;
        }
    }

    /**
     * 订单状态2总数
     * @return
     */
    @RequestMapping(value = "count2",method = RequestMethod.POST)
    @ResponseBody
    public Integer orderCount2(){
        int count2 = orderShowService.orderCount(1001, 2);
        return count2;
    }

    /**
     * 订单状态3总数
     * @return
     */
    @RequestMapping(value = "count3",method = RequestMethod.POST)
    @ResponseBody
    public Integer orderCount3(){
        int count3 = orderShowService.orderCount(1001, 3);
        return count3;
    }

    /**
     * 订单状态4总数
     * @return
     */
    @RequestMapping(value = "count4",method = RequestMethod.POST)
    @ResponseBody
    public Integer orderCount4(){
        int count4 = orderShowService.orderCount(1001, 4);
        return count4;
    }

    @RequestMapping(value = "page",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Integer> selectByPage1(Integer pageNum, Integer pageSize) {
//        System.out.println(pageNum+","+pageSize);
//        List<OrderShow> list = orderShowService.selectByPage1(pageNum,pageSize);
//        PageHelper.startPage(pageNum,pageSize);
        Integer totalSize = orderShowService.orderCount(1001,2);
        Map<String,Integer> map = new HashMap<>();
        map.put("totalSize",totalSize);
        map.put("pageNum",pageNum);
        map.put("pageSize",pageSize);
//        System.out.println("55555"+totalSize);
        return map;
    }



}
